from abc import ABC, abstractmethod
from typing import List

from forward.api.admin.schemas.setting import SettingCopyrightInSchema
from forward.utils.config import ConfigUtil
from forward.utils.tools import ToolsUtil


class SettingCopyrightService:
    """网站备案服务实现类"""

    async def detail(self):
        """获取网站备案信息"""
        config = await ConfigUtil.get_val("website", "copyright", "")
        if not config:
            config = "{}"
        return ToolsUtil.json_to_map(config)

    async def save(self, copyright_in: SettingCopyrightInSchema):
        """保存网站备案信息"""
        await ConfigUtil.set("website", "copyright", copyright_in.model_dump_json())

    @classmethod
    async def instance(cls):
        """实例化"""
        return cls()
